package com.greatmay.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;

import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;

@Entity
@Table(name = "category")
@Indexed
@XmlRootElement
public class Category extends BaseObject implements Comparable<Category>{
    private static final long serialVersionUID = -7509802253014477861L;
    public static final String SPERATER = ",";
    private Long id;
    private String name;
    private String parentCategory;
    private String description;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @DocumentId
    public Long getId() {
        return id;
    }
    @Column(nullable=false, unique=true)
    @Field
    public String getName() {
        return name;
    }
    @Column(nullable=false)
    @Field
    public String getParentCategory() {
        return parentCategory;
    }
    @Column
    public String getDescription() {
        return description;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public void setName(String name) {
        this.name = name;
    }
    public void setParentCategory(String parentCategory) {
        this.parentCategory = parentCategory;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    @Override
    public int compareTo(Category o) {
        if (o == null) return 1;
        int result = this.getParentCategory().compareTo(o.getParentCategory());
        if (result != 0) return result;
        return this.getName().compareTo(o.getName());
    }
}
